/************************************************************************
 * The code is owned by mainframer.cn and Shang Tao
 * Without aproval of mainframer.cn and Shang Tao, removing the copyright
 * infomation is regarded as invassion of proprietary copyright
 ***********************************************************************/
package com.mr.qa.util.mail;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;

import javax.activation.DataSource;
import javax.mail.internet.MimeUtility;

import org.apache.struts.upload.FormFile;

class InputStreamDataSource implements DataSource
{
    private FormFile formFile;
    public InputStreamDataSource(FormFile formFile)
    {
        this.formFile = formFile;
    }

    public String getContentType()
    {
        return this.formFile.getContentType();
    }
    
    public InputStream getInputStream() throws FileNotFoundException, IOException
    {
        return this.formFile.getInputStream();
    }
    
    public String getName()
{
        
        try
        {
            /*
            System.out.println("com.mr.qa.util.mail.InputStreamDataSource method getName() file name="+this.formFile.getFileName());
            MimeUtility.decodeText("this.formFile.getFileName()");
            return new String(this.formFile.getFileName().getBytes("iso8859-1"),"GBK");
            */
            return MimeUtility.decodeText(this.formFile.getFileName());
        }
        catch(UnsupportedEncodingException uee)
        {
            System.out.println("com.mr.qa.util.mail.InputStreamDataSource method getName() UnsupportedEncodingException "+uee);
        }
        return this.formFile.getFileName();
    }
    
    public OutputStream getOutputStream()
    {
        return null;
    }

    public void setFormFile(FormFile formFile)
    {
        this.formFile = formFile;
    }
    
    public FormFile getFormFile()
    {
        return formFile;
    }
}
